package com.ruoyi.mp.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.db.domain.system.MpClient;
import com.ruoyi.db.domain.system.MpClientReturnRecord;
import com.ruoyi.mp.annotion.Login;
import com.ruoyi.mp.annotion.LoginUser;
import com.ruoyi.mp.service.IMpClientReturnRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户参与定返活动记录Controller
 * 
 * @author ruoyi
 * @date 2022-08-05
 */
@Api(value = "用户参与定返活动记录",tags ="用户参与定返活动记录")
@RestController
@RequestMapping("/smp/client/return/record")
public class MpClientReturnRecordController extends BaseController
{
    private static Logger log = LoggerFactory.getLogger(MpClientReturnRecordController.class);
    @Autowired
    private IMpClientReturnRecordService mpClientReturnRecordService;

    /**
     * 查询用户参与定返活动记录列表
     */
    @Login
    @ApiOperation(value = "查询用户参与定返活动记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpClientReturnRecord",value="用户参与定返活动记录",paramType="form")
    })
    @GetMapping("/list")
    public TableDataInfo list(MpClientReturnRecord mpClientReturnRecord, @LoginUser MpClient client)
    {
        try {
            startPage();
            mpClientReturnRecord.setClientId(client.getClientId());
            List<MpClientReturnRecord> list = mpClientReturnRecordService.selectMpClientReturnRecordList(mpClientReturnRecord);
            return getDataTable(list);
        }catch (Exception e){
            log.error("用户参与定返活动记录发生异常",e);
        }
        return null;
    }


    /**
     * 用户参与定返活动
     */
    @Login
    @ApiOperation(value = "用户参与定返活动")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpClientReturnRecord",value="用户参与定返活动记录",dataType="MpClientReturnRecord")
    })
    @PostMapping
    public AjaxResult add(@RequestBody MpClientReturnRecord mpClientReturnRecord,@LoginUser MpClient client)
    {
        try {
            if(client.getIsVirtual()!=null&&client.getIsVirtual()==1){
                return AjaxResult.success("虚拟号无法参与定返活动");
            }
            mpClientReturnRecordService.insertMpClientReturnRecord(mpClientReturnRecord,client);
            return AjaxResult.success("参与成功");
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @ApiOperation(value = "获取【请填写功能名称】详细信息")
    @ApiImplicitParam(name="id",value="【请填写功能名称】")
    @GetMapping(value = "/info")
    public TableDataInfo getInfo( Long id)
    {
        try {
            startPage();
            return getDataTable(mpClientReturnRecordService.getPcClientRaiseRecordList(id));
        }catch (Exception e){
            return null;
        }
    }



}
